package com.bwie.controller;

import com.alibaba.fastjson.JSON;
import com.bwie.domain.Log;
import com.bwie.domain.Shop;
import com.bwie.mapper.LogMapper;
import com.bwie.poi.ExcelUtil;
import com.bwie.service.ShopService;
import com.bwie.utils.R;
import com.bwie.vo.MessageVo;
import com.bwie.vo.PageInfoVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author: lrz
 * @Date: 2024/10/21 10:30
 * @Description:
 **/
@RestController
@RequestMapping("/shop/shop")
@Slf4j
public class ShopController {

    @Autowired
    ShopService shopService;


    @PostMapping("/list")
    public R list(@RequestBody PageInfoVo pageInfoVo){
        return shopService.list(pageInfoVo);
    }

    @PostMapping("/addShop")
    public R addShop(@RequestBody Shop shop){
        return shopService.addShop(shop);
    }

    @PostMapping("/updateShop/{id}/{flag}")
    public R updateShop(@PathVariable("id")Integer id,@PathVariable("flag")Integer flag){
        return shopService.typeId(id,flag);
    }

    @PostMapping("/scimg")
    public R scimg(@RequestPart("file")MultipartFile file) throws IOException {
        return shopService.scimg(file);
    }

    @PostMapping("/xgShop")
    public R updateShop(@RequestBody Shop shop){
        return shopService.updateShop(shop);
    }

    @PostMapping("/pdDel")
    public R pdDel(@RequestBody ArrayList<Integer> ids){
        return shopService.pdDel(ids);
    }

    @GetMapping("/exclShop")
    public void exclShop(HttpServletResponse httpServletResponse){

        List<Shop> shopArrayList = shopService.getShopList();

        ExcelUtil<Shop> shopExcelUtil = new ExcelUtil<>(Shop.class);
        shopExcelUtil.exportExcel(httpServletResponse,shopArrayList,"商品数据");
    }


    @PostMapping("/typeList")
    public R typeList(){
        return shopService.typeList();
    }

}
